import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Main extends JFrame// implements WindowListener
{
  private static int DEFAULT_FPS = 20;

  private CodeScreenPanel wp;

  private int pWidth, pHeight;   // diemensions of the panel

  public Main(long period)
  { super("TextDohicky");


    setUndecorated(true);
    pack();   // first one (the GUI doesn't include the JPanel yet)
    setResizable(false);   // sizes may change when non-resizable
    calcSizes();
    setResizable(true);


    Container c = getContentPane();
    wp = new CodeScreenPanel(period, pWidth, pHeight);
    c.add(wp, "Center");
    pack();  // second, after JPanel added

//    addWindowListener( this );

    addComponentListener( new ComponentAdapter() {
      public void componentMoved(ComponentEvent e)
      /* Called by the Component listener when the JFrame is
         moved. Put it back in its original position. */
      {  setLocation(0,0);  }
    });

    setResizable(false);
    setVisible(true);
  }  // end of WormChase() constructor

  private void calcSizes(){
    GraphicsConfiguration gc = getGraphicsConfiguration();
    Rectangle screenRect = gc.getBounds();

    //Toolkit tk = Toolkit.getDefaultToolkit();
    //Insets desktopInsets = tk.getScreenInsets(gc);

   // Insets frameInsets = getInsets();     // only works after a pack() call


    pWidth = screenRect.width;// - (desktopInsets.left + desktopInsets.right)
                             // - (frameInsets.left + frameInsets.right);

    pHeight = screenRect.height;// - (desktopInsets.top + desktopInsets.bottom)
                                //- (frameInsets.top + frameInsets.bottom);
  }



  public static void main(String args[])
  {
    int fps = DEFAULT_FPS;
    long period = (long) 1000.0/fps;
    System.out.println("fps: " + fps + "; period: " + period + " ms");

    new Main(period*1000000L);    // ms --> nanosecs
  }

}


